/*
 * @Description:
 * @Author: zhaolei
 * @Date: 2023-05-25 15:10:40
 */
import { BROADCAST_TYPE, BROADCAST_TYPE_LIST } from '@/const/type';
export const tableOption = (isComment) => {
  return {
    ...window.$crudMixins.tableOptions,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    menuWidth: 80,
    searchLabelWidth: 130,
    labelWidth: 130,
    viewBtn: false,
    emptyBtn: false,
    submitBtn: false,
    detail: true,
    row: true,
    column: [
      {
        label: '文章标题',
        prop: 'title',
        rules: [
          {
            required: true,
            message: '请输入文章标题',
          },
          {
            min: 1,
            max: 25,
            message: '长度不能超过25个字符',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '关联账号',
        remote: true,
        prop: 'userPhone',
        type: 'select',
        filterable: true,
        clearable: true,
        dicUrl: `/app/appuser/list/official?param={{key}}`,
        props: {
          label: 'nickname',
          value: 'phone',
        },
        typeformat(item, label, value) {
          return `${item[label]}（${item[value]}）`;
        },
        rules: [
          {
            required: true,
            message: '请选择关联账号',
          },
        ],
      },
      {
        label: '文章标签',
        prop: 'label',
        type: 'select',
        dicUrl: '/admin/dict/type/article_tag',
        multiple: true,
        rules: [
          {
            required: true,
            message: '请选择文章标签',
          },
        ],
      },
    ],
    group: [
      {
        label: '素材图片/视频',
        prop: 'group1',
        labelWidth: 110,
        column: [
          {
            label: '素材类型',
            prop: 'fileType',
            type: 'radio',
            row: true,
            span: 12,
            dicData: BROADCAST_TYPE_LIST,
            rules: [
              {
                required: true,
                message: '请选择素材类型',
              },
            ],
            control: (val, form) => {
              if (val === BROADCAST_TYPE.PICTURE) {
                return {
                  petPicture: {
                    display: true,
                  },
                  petVideo: {
                    display: false,
                  },
                };
              } else {
                return {
                  petPicture: {
                    display: false,
                  },
                  petVideo: {
                    display: true,
                  },
                };
              }
            },
          },
          {
            label: '',
            display: true,
            prop: 'petPicture',
            type: 'upload',
            // listType: 'picture-img',
            listType: 'picture-card',
            fileSize: 10 * 1024,
            fileType: 'img', //img/video/audio
            propsHttp: {
              name: 'hash',
              url: 'key',
            },
            multiple: true,
            oss: 'qiniu',
            cropperOption: {
              // autoCropWidth: 187.5,
              // autoCropHeight: 250,
              enlarge: 2,
              fixed: true,
              fixedNumber: [0.75, 1], // 截图框的宽高比例
            },
            tip: '请上传jpg/png/jpeg/webp/heic类型的文件，且大小不超过10M，最多可上传9张图片',
            row: true,
            span: 24,
            limit: 9,
            accept: '.jpg,.png,.jpeg,.webp,.heic',
            rules: [
              { required: true, message: '请上传宣传图片', trigger: 'blur' },
            ],
          },
          {
            label: '',
            prop: 'petVideo',
            type: 'upload',
            fileSize: 50 * 1024, // 写在这里直接拦截没有提示
            // listType: 'picture-card',
            listType: 'picture-img',
            fileType: 'video', //img/video/audio
            propsHttp: {
              name: 'hash',
              url: 'key',
            },
            oss: 'qiniu',
            tip: '视频时长仅支持3分钟以内，建议优先9-30秒，最多可上传1个视频',
            row: true,
            span: 24,
            accept: '.mp4, .mpeg, .WMV, .mov',
            limit: 1,
            rules: [
              { required: true, message: '请上传宣传视频', trigger: 'blur' },
            ],
          },
        ],
      },
      {
        label: '文章内容',
        prop: 'group2',
        labelWidth: 0,
        column: [
          {
            label: '',
            prop: 'content',
            type: 'textarea',
            span: 24,
          },
        ],
      },
      {
        label: '被举报评论',
        prop: 'groupComment',
        labelWidth: 0,
        display: isComment,
        column: [
          {
            type: 'textarea',
            label: '',
            prop: 'commentContent',
            minRows: 7,
            span: 24,
          },
        ],
      },
    ],
  };
};
